package ani.trainning.cacobatph;

import java.util.List;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import ani.trainning.cacobatph.dac._DAC;
import ani.trainning.cacobatph.das._Entete;

public class THR5_QuittancePdf {

	public static final int FILE_CREATED = 10;
	public static final int FILE_CREATING = 11;
	public static final int FILE_NOT_CREATED = -10;

	private final Handler handler;
	private final Context context;

	public THR5_QuittancePdf(Context context, Handler handler){
		this.context = context;
		this.handler = handler;
	}

	public Thread createThreadDac(final _Quittance quittance, final List<_DAC> dacs, final String typeDac){
		return new Thread(){
			@Override
			public void run(){
				try {
					String path = pdfTool.createQuittanceDacPdf(context, quittance, dacs, typeDac);

					Message msg = new Message();
					msg.what = FILE_CREATED;
					msg.obj = path;
					handler.sendMessage(msg);
				} catch (Exception e) {
					Log.i("chargement", "" + e.getMessage());
					handler.sendEmptyMessage(FILE_NOT_CREATED);
				}
			}
		};
	}

	public Thread createThreadDas(final _Quittance quittance, final _Entete entete, final String typeDas){
		return new Thread(){
			@Override
			public void run(){
				try {
					sleep(2000);
					String path = pdfTool.createQuittanceDasPdf(context, quittance, entete, typeDas);

					Message msg = new Message();
					msg.what = FILE_CREATED;
					msg.obj = path;
					handler.sendMessage(msg);
				} catch (Exception e) {
					Log.i("chargement", "" + e.getMessage());
					handler.sendEmptyMessage(FILE_NOT_CREATED);
				}
			}
		};
	}
}
